package com.ruoyi.my.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.my.domain.MyChildrenInfo;
import com.ruoyi.my.service.IMyChildrenInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 儿女信息Controller
 *
 * @author ruoyi
 * @date 2022-11-10
 */
@RestController
@RequestMapping("/children/info")
public class MyChildrenInfoController extends BaseController
{
    @Autowired
    private IMyChildrenInfoService myChildrenInfoService;

    /**
     * 查询儿女信息列表
     */
    @PreAuthorize("@ss.hasPermi('children:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyChildrenInfo myChildrenInfo)
    {
        startPage();
        List<MyChildrenInfo> list = myChildrenInfoService.selectMyChildrenInfoList(myChildrenInfo);
        return getDataTable(list);
    }

    @GetMapping("/count")
    public AjaxResult count()
    {
        List<MyChildrenInfo> list = myChildrenInfoService.countSexNumber();
        return success(list);
    }

    /**
     * 导出儿女信息列表
     */
    @PreAuthorize("@ss.hasPermi('children:info:export')")
    @Log(title = "儿女信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyChildrenInfo myChildrenInfo)
    {
        List<MyChildrenInfo> list = myChildrenInfoService.selectMyChildrenInfoList(myChildrenInfo);
        ExcelUtil<MyChildrenInfo> util = new ExcelUtil<MyChildrenInfo>(MyChildrenInfo.class);
        util.exportExcel(response, list, "儿女信息数据");
    }

    /**
     * 获取儿女信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('children:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(myChildrenInfoService.selectMyChildrenInfoById(id));
    }

    /**
     * 新增儿女信息
     */
    @PreAuthorize("@ss.hasPermi('children:info:add')")
    @Log(title = "儿女信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyChildrenInfo myChildrenInfo)
    {
        return toAjax(myChildrenInfoService.insertMyChildrenInfo(myChildrenInfo));
    }

    /**
     * 修改儿女信息
     */
    @PreAuthorize("@ss.hasPermi('children:info:edit')")
    @Log(title = "儿女信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyChildrenInfo myChildrenInfo)
    {
        return toAjax(myChildrenInfoService.updateMyChildrenInfo(myChildrenInfo));
    }

    /**
     * 删除儿女信息
     */
    @PreAuthorize("@ss.hasPermi('children:info:remove')")
    @Log(title = "儿女信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myChildrenInfoService.deleteMyChildrenInfoByIds(ids));
    }
}
